﻿package mortal.game.view.common.tooltip.tooltips
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.util.*;
    import mortal.game.view.shopMall.view.*;

    public class ToolTipEquipmentXiLianYuLan extends ToolTipScaleBg implements IToolTipBaseItemComparable
    {
        private var _txtName:GTextFiled;
        private var _icon:ShopSellItem;
        private var _bmpEquiped:Bitmap;
        private var _txtStrenLv:BitmapNumberText;
        private var _lockIcon:GBitmap;
        private var _txtBind:GTextFiled;
        private var _bmpZDL:GBitmap;
        private var _bmpFight:BitmapNumberText;
        private var _txtSuitType:GTextFiled;
        private var _txtLevel:GTextFiled;
        private var _txtCareer:GTextFiled;
        private var _txtXilian:GTextFiled;
        private var _txtXilian2:GTextFiled;
        private var _txtXilianLeft:AutoLayoutTextContainer;
        private var _txtXilianRight:AutoLayoutTextContainer;
        private var _spBg:GSprite;
        private var _bgs:Array;
        private var _line1:ScaleBitmap;
        private var _line2:ScaleBitmap;
        private var _line3:ScaleBitmap;
        private var _txtTips:GTextFiled;
        private var _data:ItemData;
        private var _info:ItemEquipInfo;
        private var _equipedData:ItemData;
        private var _useItemExInfo:ItemExInfo;
        private var _strenLv:int;

        public function ToolTipEquipmentXiLianYuLan()
        {
            this.createChildren();
            paddingBottom = 8;
            paddingLeft = 12;
            paddingRight = 8;
            paddingTop = 8;
            return;
        }// end function

        public function setBuyback(param1:int) : void
        {
            return;
        }// end function

        public function setEquipedData(param1:Object) : void
        {
            return;
        }// end function

        public function set equiped(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._bmpEquiped == null)
                {
                    this._bmpEquiped = UIFactory.bitmap(ImagesConst.EquipedLabel, -10, 18);
                }
                contentContainer2D.addChild(this._bmpEquiped);
            }
            else
            {
                DisplayUtil.removeMe(this._bmpEquiped);
            }
            return;
        }// end function

        override public function set data(param1) : void
        {
            this._data = param1 as ItemData;
            if (this._data == null)
            {
                return;
            }
            super.data = this._data;
            this._info = this._data.itemInfo as ItemEquipInfo;
            setBg(ToolTipUtil.getBgNameByColor(this._info.color));
            this.updateTopPart();
            var _loc_2:* = this._equipedData != null && this._equipedData.extInfo != null;
            var _loc_3:* = this._data;
            if (_loc_2)
            {
                _loc_3 = this._equipedData;
            }
            this.updateXiLianAtrr(_loc_3);
            var _loc_4:* = StrengUtil.getEquipHotAttrType(this._data.itemInfo.type);
            var _loc_5:* = ForgingUtil.instance.getAttrNameByType(_loc_4);
            this._txtXilian2.htmlText = Language.getStringByParam(20777, _loc_5);
            if (this._txtXilianLeft.parent == null)
            {
                contentContainer2D.addChild(this._txtXilianLeft);
            }
            if (this._txtXilianRight.parent == null)
            {
                contentContainer2D.addChild(this._txtXilianRight);
            }
            this.updateLayout();
            _scaleBg.setSize(252, paddingTop + paddingBottom + this._txtTips.y + 20);
            this.updateName();
            return;
        }// end function

        override public function get width() : Number
        {
            return 252;
        }// end function

        private function updateLayout() : void
        {
            var _loc_1:int = 0;
            _loc_1 = this._line2.y + 11;
            this._spBg.y = _loc_1;
            this._txtXilianLeft.y = _loc_1;
            this._txtXilianRight.y = _loc_1;
            _loc_1 = _loc_1 + (this._txtXilianLeft.height + 10);
            this._line3.y = _loc_1;
            _loc_1 = _loc_1 + 4;
            this._txtTips.y = _loc_1;
            return;
        }// end function

        private function addXiLianBg(param1:int) : void
        {
            if (this._bgs == null)
            {
                this._bgs = [];
            }
            var _loc_2:* = this._bgs[param1];
            if (_loc_2 == null)
            {
                _loc_2 = UIFactory.bg(0, 23 * param1, 178, 20, this._spBg, ImagesConst.ToolTipXiLianYLBg);
                this._bgs[param1] = _loc_2;
            }
            _loc_2.y = 23 * param1;
            return;
        }// end function

        private function updateXiLianAtrr(param1:ItemData) : void
        {
            var _loc_5:AttributeData = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:uint = 0;
            var _loc_9:GTextFiled = null;
            var _loc_10:GTextFiled = null;
            var _loc_11:String = null;
            var _loc_2:* = EquipmentUtil.getEquipmentXiLianAttrs(param1, this._useItemExInfo);
            var _loc_3:* = _loc_2.length;
            this._txtXilianLeft.split(_loc_3);
            this._txtXilianRight.split(_loc_3);
            if (this._bgs != null)
            {
                DisplayUtil.delNotUse(this._bgs, _loc_3);
            }
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                this.addXiLianBg(_loc_4);
                if (this._txtXilianLeft.getTextByIndex(_loc_4) == null)
                {
                    this._txtXilianLeft.addNewText(220, "", 12, GlobalStyle.colorLanUint);
                }
                if (this._txtXilianRight.getTextByIndex(_loc_4) == null)
                {
                    this._txtXilianRight.addNewText(220, "", 12, GlobalStyle.colorLanUint);
                }
                _loc_5 = _loc_2[_loc_4];
                _loc_6 = parseInt(_loc_5.attrName);
                _loc_7 = EquipRefreshConfig.instance.getMaxStarLevel(param1.itemInfo.level);
                _loc_8 = ForgingUtil.instance.getPropColor(_loc_6, _loc_7);
                this._txtXilianLeft.setText(_loc_4, " ");
                this._txtXilianRight.setText(_loc_4, " ");
                _loc_9 = this._txtXilianLeft.getTextByIndex(_loc_4);
                _loc_10 = this._txtXilianRight.getTextByIndex(_loc_4);
                _loc_9.textColor = _loc_8;
                _loc_10.textColor = _loc_8;
                _loc_9.text = _loc_5.name + "  +" + (_loc_5.value - _loc_5.baseValue);
                _loc_11 = Language.getStringByParam(20778, _loc_6);
                if (_loc_5.baseValue > 0)
                {
                    _loc_11 = _loc_11 + ("+" + _loc_5.baseValue);
                }
                _loc_10.text = _loc_11;
                _loc_4++;
            }
            return;
        }// end function

        private function updateTopPart() : void
        {
            var _loc_1:* = ItemsUtil.isBind(this._data);
            this._icon.itemData = this._data;
            this._icon.isBind = _loc_1;
            if (this._strenLv <= 0)
            {
                this._txtStrenLv.text = "";
            }
            else
            {
                this._txtStrenLv.text = "+" + this._strenLv.toString();
            }
            this._txtStrenLv.x = 69 - this._txtStrenLv.width;
            this._lockIcon.visible = _loc_1;
            if (_loc_1)
            {
                this._txtBind.textColor = GlobalStyle.colorHongUint;
                this._txtBind.text = Language.getString(20206);
                this._txtBind.x = 100;
            }
            else
            {
                this._txtBind.textColor = GlobalStyle.colorLvUint;
                this._txtBind.text = Language.getString(20205);
                this._txtBind.x = 79;
            }
            this._bmpFight.text = EquipmentUtil.getEquipCombat(this._data, 0, this._useItemExInfo).toString();
            var _loc_2:* = GameDefConfig.instance.getEquipName(this._info.type);
            if (this._info.suitGroup > 0)
            {
                _loc_2 = _loc_2 + Language.getString(20771);
            }
            this._txtSuitType.text = _loc_2;
            this._txtLevel.text = Language.getString(30011) + "：" + this._info.level.toString();
            this._txtCareer.text = GameDefConfig.instance.getCarrer(this._info.career);
            if (CareerUtil.isCareerSuit(this._info.career, Cache.instance.role.entityInfo.career))
            {
                this._txtCareer.textColor = 15911263;
            }
            else
            {
                this._txtCareer.textColor = 16711680;
            }
            return;
        }// end function

        private function updateName() : void
        {
            this._txtName.width = _scaleBg.width;
            this._txtName.htmlText = ItemsUtil.getItemWholeName(this._data, true, 0, false, this._strenLv);
            this._txtName.x = -6;
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", -6, 0, 220, 25, this, _loc_1);
            this._icon = UICompomentPool.getUICompoment(ShopSellItem);
            this._icon.x = 0;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._icon.createDisposedChildren();
            this.addChild(this._icon);
            this._icon.isShowLock = false;
            this._icon.isShowArroundEffect = false;
            _loc_1 = GlobalStyle.embedNumberTf;
            _loc_1.color = GlobalStyle.colorHuangUint;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._txtStrenLv = UIFactory.bitmapNumberText(this._icon.x, this._icon.y + 50, "FightInfoNum.png", 12, 15, -1, this);
            this._lockIcon = UIFactory.bitmap(ImagesConst.LockIcon, 81, 34, contentContainer2D);
            this._txtBind = UIFactory.gTextField("", 100, 30, 100, 20, contentContainer2D);
            this._bmpZDL = UIFactory.gBitmap(ImagesConst.ToolTipCombat, 79, 78, contentContainer2D);
            this._bmpFight = UIFactory.bitmapNumberText(127, 78, "EquipToolTipCombat.png", 14, 16, -2, contentContainer2D, 10);
            this._txtSuitType = UIFactory.gTextField("", 155, 30, 100, 20, contentContainer2D);
            this._txtLevel = UIFactory.gTextField("", 155, 52, 100, 20, contentContainer2D);
            this._txtCareer = UIFactory.gTextField("", 79, 52, 100, 20, contentContainer2D);
            this._txtCareer.textColor = 15911263;
            _loc_1 = GlobalStyle.textFormatHuang2;
            _loc_1.size = 13;
            this._txtXilian = UIFactory.gTextField("", 12, 124, 240, 24, contentContainer2D, _loc_1);
            this._txtXilian.htmlText = Language.getString(20779);
            _loc_1 = GlobalStyle.textFormatPutong;
            _loc_1.size = 13;
            this._txtXilian2 = UIFactory.gTextField("", 12, 150, 240, 20, contentContainer2D, _loc_1);
            this._txtXilian2.htmlText = Language.getString(20780);
            this._spBg = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this._spBg.x = 8;
            this._spBg.y = this._txtXilian.y + 22;
            contentContainer2D.addChild(this._spBg);
            this._txtXilianLeft = new AutoLayoutTextContainer();
            this._txtXilianLeft.x = 12;
            this._txtXilianLeft.y = this._spBg.y - 5;
            this._txtXilianLeft.verticalGap = -1;
            contentContainer2D.addChild(this._txtXilianLeft);
            this._txtXilianRight = new AutoLayoutTextContainer();
            this._txtXilianRight.x = 96;
            this._txtXilianRight.y = this._txtXilianLeft.y;
            this._txtXilianRight.verticalGap = -1;
            contentContainer2D.addChild(this._txtXilianRight);
            this._line1 = UIFactory.bg(0, 148, 256, 2, contentContainer2D, ImagesConst.SplitLine);
            this._line2 = UIFactory.bg(0, 174, 256, 2, contentContainer2D, ImagesConst.SplitLine);
            this._line3 = UIFactory.bg(0, 331, 256, 2, contentContainer2D, ImagesConst.SplitLine);
            this._txtTips = UIFactory.gTextField("", 12, 315, 240, 22, contentContainer2D);
            this._txtTips.htmlText = Language.getString(20781);
            return;
        }// end function

    }
}
